home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / jpl_c.zip / FSCANF.C < prev    next >
Text File  |  1986-05-18  |  2KB  |  49 lines

  1. /* 1.1  01-08-86                         (fscanf.c)
  2.  ************************************************************************
  3.  *            Robert C. Tausworthe                *
  4.  *            Jet Propulsion Laboratory            *
  5.  *            Pasadena, CA 91009        1986        *
  6.  ************************************************************************/
  7.  
  8. #include "defs.h"
  9. #include "stdtyp.h"
  10. #include "stdio.h"
  11.  
  12. /*----------------------------------------------------------------------*/
  13.  
  14. LOCAL FILE *Fp;
  15. LOCAL int lastch;
  16.  
  17. /************************************************************************/
  18.  
  19. fscanf(fp, fmt, arg)    /* Read FILE fp using format fmt, and deposit
  20.                information into arguments in arg list. Return
  21.                count of items read, or EOF on error.    */
  22. /*----------------------------------------------------------------------*/
  23. FILE *fp;
  24. STRING fmt;
  25. unsigned *arg;
  26. {
  27.     int _getc(), unformat();
  28.  
  29.     lastch = EOF;
  30.     Fp = fp;
  31.     return unformat(_getc, fmt, &arg);
  32. }
  33.  
  34. /************************************************************************/
  35.     LOCAL
  36. _getc(forward)        /* Return a character from the stdin.
  37.                If forward is TRUE, get next character and
  38.                advance; else, unget the character unless the
  39.                end has been reached. Return EOF if so.    */
  40. /*----------------------------------------------------------------------*/
  41. BOOL forward;
  42. {
  43.     METACHAR getca(), ungetc();
  44.  
  45.     return (lastch = (forward ? (feof(Fp) ? EOF : getca(Fp))
  46.         : ungetc(lastch, Fp)));
  47. }
  48.  
  49.